package com.example;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private final String username="root";
    private final String password="123";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uname= req.getParameter("username");
        String pwd=req.getParameter("password");
        System.out.println("收到用户名："+uname);
        System.out.println("收到密码："+pwd);
        if(username.equals(uname) && password.equals(pwd))
        {
            resp.sendRedirect(req.getContextPath()+"/stu");
        }
        else{
            req.setAttribute("msg","用户名或密码错误");
            req.getRequestDispatcher("Login.jsp").forward(req,resp);
        }
    }
}
